import cv2
import numpy as np
import random

'''
 cv2.FONT_ITALIC：斜体字的标志
 cv2.FONT_HERSHEY_PLAIN：小尺寸无衬线字体
 cv2.FONT_HERSHEY_SIMPLEX：正常大小的无衬线字体
 cv2.FONT_HERSHEY_DUPLEX：正常大小的无衬线字体（比FONT_HERSHEY_SIMPLEX更复杂）
 cv2.FONT_HERSHEY_COMPLEX：正常大小的衬线字体
 cv2.FONT_HERSHEY_TRIPLEX：正常大小的衬线字体（比FONT_HERSHEY_COMPLEX更复杂）
 cv2.FONT_HERSHEY_SCRIPT_SIMPLEX：手写体字体
 cv2.FONT_HERSHEY_SCRIPT_COMPLEX（比FONT_HERSHEY_SCRIPT_SIMPLEX的更复杂）

'''
fontFace_list = [
    cv2.FONT_ITALIC,
    cv2.FONT_HERSHEY_PLAIN,
    cv2.FONT_HERSHEY_SIMPLEX,
    cv2.FONT_HERSHEY_DUPLEX,
    cv2.FONT_HERSHEY_COMPLEX,
    cv2.FONT_HERSHEY_TRIPLEX,
    cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
    cv2.FONT_HERSHEY_SCRIPT_COMPLEX
]


img = cv2.imread(r'D:\VOCtrainval_11-May-2012\JPEGImages\2007_000027.jpg')
mask = np.zeros(shape=img.shape, dtype=np.uint8)

for i in range(random.randint(2, 12)):
    text = ''
    for i in range(11):
        text += str(random.randint(0, 9))
    fontFace = fontFace_list[random.randint(0, len(fontFace_list)-1)]
    fontScale = random.random() * 1.5 + 0.5
    color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
    thickness = random.randint(1, 3)
    x, y = int(mask.shape[1]*random.random()), int(mask.shape[0]*random.random())

    text_size = cv2.getTextSize(text, fontFace, fontScale, thickness)
    w, h = text_size[0]

    cv2.putText(mask, text, (x, y), fontFace, fontScale, color, thickness)
    # cv2.rectangle(img, (x, y), (x+w, y-h), (0, 0, 255), 1)

for i in range(10, -1, -1):
    watermark_img = cv2.addWeighted(img, 1, mask, i*0.1, 0)
    
    cv2.imshow('a', watermark_img)
    cv2.waitKey(0)